package com.example.common.util;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.experimental.UtilityClass;

@UtilityClass
public class PageUtils {

    /**
     * 获取分页对象
     */
    public <T> Page<T> getPage(PageQuery query) {
        return new Page<>(query.getPageNum(), query.getPageSize());
    }

    /**
     * 获取分页对象（带排序）
     */
    public <T> Page<T> getPage(PageQuery query, String... orderByColumns) {
        Page<T> page = new Page<>(query.getPageNum(), query.getPageSize());
        if (orderByColumns != null && orderByColumns.length > 0) {
            for (String orderBy : orderByColumns) {
                page.addOrder(OrderItem.asc(orderBy));
            }
        }
        return page;
    }
} 